﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HVAC
{
	public partial class AlignmentForm : System.Windows.Forms.Form
	{
		public AlignmentForm()
		{
			this.InitializeComponent();
			base.Icon = Resource.YArchitechIcon;
			this.GetUserSetting();
			new YJKProcessTools().ShowInTaskbarChange(this);
			if (this.rdoReference.Checked)
			{
				this.checkBox1.Checked = false;
				this.isUserDate = false;
				this.checkBox1.Enabled = false;
				this.hyTextBox1.Enabled = false;
			}
		}

		private void GetUserSetting()
		{
			this.hyTextBox1.Enabled = false;
			string[] ductAlignTypeText = this.userSetting.GetDuctAlignTypeText(true);
			string b = ductAlignTypeText[0];
			if ("Middle" == b)
			{
				this.rdoMiddle.Checked = true;
				if (ductAlignTypeText[1] == "true")
				{
					this.checkBox1.Enabled = true;
					if (this.checkBox1.Checked)
					{
						this.hyTextBox1.Enabled = true;
					}
				}
				else
				{
					this.checkBox1.Checked = false;
				}
			}
			else if ("Top" == b)
			{
				this.rdoTop.Checked = true;
				if (ductAlignTypeText[1] == "true")
				{
					this.checkBox1.Enabled = true;
					if (this.checkBox1.Checked)
					{
						this.hyTextBox1.Enabled = true;
					}
				}
				else
				{
					this.checkBox1.Checked = false;
				}
			}
			else if ("Bottom" == b)
			{
				this.rdoBottom.Checked = true;
				if (ductAlignTypeText[1] == "true")
				{
					this.checkBox1.Enabled = true;
					if (this.checkBox1.Checked)
					{
						this.hyTextBox1.Enabled = true;
					}
				}
				else
				{
					this.checkBox1.Checked = false;
				}
			}
			else if ("Reference" == b)
			{
				this.rdoReference.Checked = true;
				this.checkBox1.Enabled = false;
				this.hyTextBox1.Enabled = false;
			}
			if (ductAlignTypeText[2] != "")
			{
				this.hyTextBox1.Text = ductAlignTypeText[2];
			}
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			string[] array = new string[3];
			if (this.rdoMiddle.Checked)
			{
				this.alignmentType = "Middle";
			}
			else if (this.rdoTop.Checked)
			{
				this.alignmentType = "Top";
			}
			else if (this.rdoBottom.Checked)
			{
				this.alignmentType = "Bottom";
			}
			else if (this.rdoReference.Checked)
			{
				this.alignmentType = "Reference";
			}
			if (this.checkBox1.Checked)
			{
				array[1] = "true";
			}
			else
			{
				array[1] = "false";
			}
			if (this.hyTextBox1.Text != "")
			{
				array[2] = this.hyTextBox1.Text;
			}
			array[0] = this.alignmentType;
			this.height = double.Parse(this.hyTextBox1.Text) / 304.8;
			this.userSetting.WriteDuctAlignTypeText(array);
			base.DialogResult = DialogResult.OK;
		}

		private void groupBox2_Enter(object sender, EventArgs e)
		{
		}

		private void checkBox1_CheckedChanged(object sender, EventArgs e)
		{
			if (this.checkBox1.Checked)
			{
				this.isUserDate = true;
				this.hyTextBox1.Enabled = true;
				return;
			}
			this.isUserDate = false;
			this.hyTextBox1.Enabled = false;
		}

		private void rdoBottom_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoBottom.Checked)
			{
				this.checkBox1.Enabled = true;
				if (this.checkBox1.Checked)
				{
					this.hyTextBox1.Enabled = true;
				}
			}
		}

		private void rdoReference_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoReference.Checked)
			{
				this.checkBox1.Enabled = false;
				this.hyTextBox1.Enabled = false;
				return;
			}
			this.checkBox1.Enabled = true;
			if (this.checkBox1.Checked)
			{
				this.hyTextBox1.Enabled = true;
			}
		}

		private void rdoTop_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoBottom.Checked)
			{
				this.checkBox1.Enabled = true;
				if (this.checkBox1.Checked)
				{
					this.hyTextBox1.Enabled = true;
				}
			}
		}

		private void rdoMiddle_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoBottom.Checked)
			{
				this.checkBox1.Enabled = true;
				if (this.checkBox1.Checked)
				{
					this.hyTextBox1.Enabled = true;
				}
			}
		}

		private void AlignmentForm_Load(object sender, EventArgs e)
		{
		}

		public string alignmentType = "Middle";

		private HVACUserSetting userSetting = new HVACUserSetting();

		public bool isUserDate;

		public double height;
	}
}
